/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.game.math.view.render;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableModel;
import org.game.math.view.domain.Examination;
import org.game.math.view.domain.ExpressionTableModel;
import org.game.math.view.domain.MathExpression;

/**
 *
 * @author nmduc
 */
class ExpressionCellRenderer extends DefaultTableCellRenderer {

  override def getTableCellRendererComponent(table:JTable , value:Any, isSelected:Boolean, hasFocus:Boolean, row:Int, column:Int):Component = {
    val component:Component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    val model:TableModel = table.getModel();
    if (model.isInstanceOf[ExpressionTableModel] ) {
      val examination:Examination = model.asInstanceOf[ExpressionTableModel].getExamination();
      val expressions = examination.expressionList.toArray;
      val expression:MathExpression  = expressions(row);
      if (examination.checked && !expression.corrected) {
        component.setForeground(Color.red);
      } else {
        if (!isSelected) {
          component.setForeground(Color.black);
        } else {
          component.setForeground(Color.white);
        }
      }
    }
    component;

  }
}
